package ch01.text00.tx01;

import java.lang.reflect.Constructor;
import java.lang.reflect.Modifier;

/**
 * 实体对象 - 基于反射实现一些测试操作
 * <p>
 * 修饰符 - Modifier
 */
public class Student {
    /**
     * 属性 - 字段 - Field
     */
    private String name;
    private int age;
    private float weight;
    private static final double PI = 3.14;

    /**
     * 构造方法 - Construct
     */
    public Student() {
    }

    public Student(String name, int age, float weight) {
        this.name = name;
        this.age = age;
        this.weight = weight;
    }

    public Student(String name, Float weight) {
        this.name = name;
        this.age = 18;
        this.weight = weight;
    }

    /**
     * 方法 - Method
     *
     * @return
     */
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public float getWeight() {
        return weight;
    }

    public void setWeight(float weight) {
        this.weight = weight;
    }

    public void hello() {
        System.out.println("你好!");
    }

    private void sleep() {
        System.out.println("睡觉了！");
    }

    public void sayHello(String who) {
        System.out.println("你好," + who);
    }

    public void sayHello(String who,int age) {
        System.out.println("你好," + who);
    }

    public int sum(int i, int j) {
        return i + j;
    }

    @Override
    public String toString() {
        return this.getName() + "," + this.getAge() + "," + this.getWeight();
    }

    /**
     * 静态方法
     */
    public static void study() {
        System.out.println("学习!");
    }

    public static void study(String sth) {
        System.out.printf("学习《%s》", sth);
    }

    public static void show() {
        try {
            // 获取 Student 类的 Class 对象
            Class<?> clazz = Student.class;

            // 获取指定构造方法
            Constructor<?> constructor = clazz.getConstructor(String.class, int.class, float.class);

            // 打印构造方法的信息
            System.out.println("构造方法名称: " + constructor.getName());
            System.out.println("构造方法参数类型: ");
            Class<?>[] paramTypes = constructor.getParameterTypes();
            for (Class<?> paramType : paramTypes) {
                System.out.println(" - " + paramType.getName());
            }
            System.out.println("构造方法修饰符: " + Modifier.toString(constructor.getModifiers()));
            System.out.println("构造方法所属类: " + constructor.getDeclaringClass().getName());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}